package com.czh.subject.domain.handler.subject;

import com.czh.subject.common.enums.SubjectTypeEnum;
import com.czh.subject.domain.entity.SubjectAnswerAndOptionBO;
import com.czh.subject.domain.entity.SubjectInfoBO;
import com.czh.subject.infra.basic.entity.SubjectBrief;
import com.czh.subject.infra.basic.service.SubjectBriefService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;


/**
 * @author caozaihui
 * @version 1.0
 * @description: 简答题策略
 * @since 2024/7/31 下午 2:55
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public SubjectTypeEnum getHandlerType() {
        return SubjectTypeEnum.BRIEF;
    }

    @Override
    public boolean add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectAnswer(subjectInfoBO.getSubjectAnswer());
        subjectBrief.setSubjectId(subjectInfoBO.getId());
        return subjectBriefService.save(subjectBrief);
    }

    @Override
    public SubjectAnswerAndOptionBO queryOptionAndAnswer(Long id) {
        SubjectBrief subjectBrief = subjectBriefService.selectBriefBySubjectId(id);
        SubjectAnswerAndOptionBO subjectAnswerAndOptionBO = new SubjectAnswerAndOptionBO();
        subjectAnswerAndOptionBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectAnswerAndOptionBO;
    }
}
